package com.sudoku.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.sudoku.utility.Locator;

public class FadeInTransitionEffect extends TransitionEffect {

    public FadeInTransitionEffect(float duration) {
        super(duration);
        time=0;
    }

    private float time;

    @Override
    public void render(Screen current, Screen next, float alpha) {
        next.render(Gdx.graphics.getDeltaTime());
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        
        ShapeRenderer sh=new ShapeRenderer();
        sh.setTransformMatrix(Locator.getCamera().view);
		sh.setProjectionMatrix(Locator.getCamera().projection);
        sh.begin(ShapeType.Filled);
        sh.setColor(0, 0, 0, 1-alpha);
        sh.rect(0, 0, ACTUAL_VIRTUAL_WIDTH, ACTUAL_VIRTUAL_HEIGHT);
        sh.end();
        
        time+=Gdx.graphics.getDeltaTime();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }

    @Override
    protected float getAlpha() {
        return 0;
    }

    @Override
    void update(float delta) {
        
    }

    @Override
    boolean isFinished() {
        if(time >= duration){
            return true;
        }
        return false;
    }

}
